package com.weiqiao.mall.repository.impl;

import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.ICommentRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("CommentRepositoryImpl")
public class CommentRepositoryImpl extends BaseMongoDaoImpl implements ICommentRepository {

    private String collection_name = "app_comment_";

    @Override
    public boolean addCommentOne(String json, int company_id) {
        return this.inSert(collection_name + company_id, json);
    }

    @Override
    public boolean addCommentMany(List<Document> documents, int company_id) {
        return this.inSertMany(collection_name + company_id, documents);
    }

    @Override
    public boolean updateCommentOne(Bson filter, Document doc, boolean flag, int company_id) {
        return this.updateOne(collection_name + company_id, filter, doc, flag);
    }

    @Override
    public boolean updateCommentMany(Bson filter, Document doc, boolean flag, int company_id) {
        return this.updateMany(collection_name + company_id, filter, doc, flag);
    }

    @Override
    public String findCommentOne(Bson filter, int company_id) {
        return this.findOne(collection_name + company_id, filter);
    }

    @Override
    public List<String> findCommentMany(Bson filter, int company_id) {
        return this.findFilter(collection_name + company_id, filter);
    }

    @Override
    public int getCount(int company_id, Document doc) {
        return this.statististics(collection_name + company_id, doc);
    }

    @Override
    public List<String> findCommentPage(int company_id, Bson doc, Pageable pageable) {
        return this.getListAndPage(collection_name + company_id, doc, pageable);
    }

    @Override
    public boolean deleteCommentOne(Bson filter, int company_id) {
        return this.deleteOne(collection_name + company_id, filter);
    }

    @Override
    public boolean deleteCommentMany(Bson filter, int company_id) {
        return this.delMany(collection_name + company_id, filter);
    }

    @Override
    public List<String> findCommentManySortLimit(Bson filter, Bson sort, int limit, int company_id) {
        return this.findFilterSortLimit(collection_name + company_id, filter, sort, limit);
    }
}
